//定义请求根路径baseUrl
const baseUrl = "http://localhost:8080";
export const getBaseUrl = () => {
    return baseUrl;
}
// 微信login封装
export const getWxLogin = () => {
    return new Promise((resolve,reject)=>{
        wx.login({
            timeout: 5000,
            success:(res)=>{
                resolve(res)
            },
            fail:(err)=>{
                reject(err)
            }
          })
    });
}

// wx getUserProfile封装
export const getUserProfile = () => {
    return new Promise((resolve,reject)=>{
        wx.getUserProfile({
            desc: '获取用户信息',
            success:(res)=>{
                resolve(res)
            },
            fail:(err)=>{
                reject(err)
            }
          })
    });
}

/*
后端请求工具 promise
*/
export const requestUtil = (params) => {

    // var start = new Date().getTime();
    // console.log(start)

    // //模拟网络延迟加载
    // while (true) {
    //     if (new Date().getTime().start > 3 * 1000) break;
    // }

    return new Promise((resolve, reject) => {
        wx.request({
            ...params,
            url: baseUrl + params.url,
            success: (result) => {
                resolve(result.data)
            },
            fail: (err) => {
                reject(err)
            },

        })
    });
}